package com.example.mall.mapper;

import com.example.mall.pojo.Category;
import com.example.mall.pojo.Level1;
import com.example.mall.pojo.Level2;
import com.example.mall.pojo.Level3;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    @Select("select * from sp_category where cat_name=#{cat_name}")
    Category selectByName(String name);

    @Select("select * from sp_category where cat_level=#{cat_level}")
    List<Category> selectByType(Integer type);

    @Select("select * from sp_category where cat_level=2 and cat_pid=#{cat_pid} ")
    List<Level3> selectByTypeThird(Integer id);

    @Select("select * from sp_category where cat_level=1 and cat_pid=#{cat_pid}")
    List<Level2> selectByTypeSecond(Integer id);

    @Select("select * from sp_category where cat_level=0 and cat_pid=#{cat_pid} ")
    List<Level1> selectByTypeFirst(Integer id);

    @Select("select * from sp_category where cat_level=0  ")
    List<Level1> selectByTypeFirst1();


    @Select("select * from sp_category ")
    List<Category> selectBy();

    @Insert("insert into sp_category(cat_name,cat_pid,cat_level) values(#{cat_name},#{cat_pid},#{cat_level})")
    int insertCategory(@Param("cat_pid") Integer pId,@Param("cat_name") String name,@Param("cat_level") Integer level);

    @Select("select * from sp_category where cat_id=#{cat_id}")
    Category selectById(Integer catId);

    @Update("update sp_category set cat_name=#{cat_name} where cat_id=#{cat_id}")
    int updateById(@Param("cat_name") String catName,@Param("cat_id") Integer catId);

    @Delete("delete from sp_category where  cat_id=#{cat_id}")
    int deleteById(Integer catId);


}
